package com.example.soscall;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.ecarx.xui.adaptapi.oncall.Call;
import com.example.soscall.BR;
import com.example.soscall.Constans;
import com.example.soscall.R;
import com.example.soscall.utils.CallHelper;




public class PhoneLiveData extends AndroidViewModel {


    /**
     * 电话状态
     */
    private MutableLiveData<Integer> phoneState = new MutableLiveData<>();
    /**
     * 救援倒计时
     */
    private MutableLiveData<Integer> rescueTime= new MutableLiveData<>();
    /**
     * 通话类型，E-call B-call
     */
    private MutableLiveData<Integer> callType= new MutableLiveData<>();
    /**
     * 通话时长
     */
    private MutableLiveData<String> duringSecond= new MutableLiveData<>();

    public PhoneLiveData(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<Integer> getPhoneState() {
        return phoneState;
    }

    public void setPhoneState(Integer phoneState) {
        this.phoneState.setValue(phoneState);
    }

    public MutableLiveData<Integer> getRescueTime() {
        return rescueTime;
    }

    public void setRescueTime(MutableLiveData<Integer> rescueTime) {
        this.rescueTime = rescueTime;
    }

    public MutableLiveData<Integer> getCallType() {
        return callType;
    }

    public void setCallType(Integer callType) {
        this.callType.setValue(callType);
    }

    public MutableLiveData<String> getDuringSecond() {
        return duringSecond;
    }

    public void setDuringSecond(String duringSecond) {
        this.duringSecond.setValue(duringSecond);
    }



    public void hungupClick(View v) {
        switch (phoneState.getValue()) {
            case Call.CALL_STATUS_IDLE:
            case Call.CALL_STATUS_START_FAILED:
            case Call.CALL_STATUS_CONNECT_FAILED:
            case Call.CALL_STATUS_DIAL_FAILED:
            case Call.CALL_STATUS_DATA_UPLOAD_FAILED:
                //case Call.CALL_STATUS_NOT_SUBSCRIBED:
            case Call.CALL_STATUS_REJECTED:
            case Call.CALL_STATUS_CALLBACK_REJECTED:
            case Call.CALL_STATUS_HANGING_UP:
            case Call.CALL_STATUS_END:
                CallHelper.getInstance().endCall();
//                            ConstantBase.IS_MAIN = false ;
                break;
            default:
                CallHelper.getInstance().endCall();
                setPhoneState(Call.CALL_STATUS_END);
//                            ConstantBase.IS_MAIN = false ;
                break;
        }

    }




}
